package com.weilaiwd.admin.web;

import com.jfinal.core.ActionKey;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.weilaiwd.admin.constant.Sql;
import com.weilaiwd.common.model.Admin;
import com.weilaiwd.common.web.BaseAction;

public class LoginAction extends BaseAction {
	
	@ActionKey("login")
	public void login() {
		
	}
	
	public void check() {
		Record record = Db.findFirst(Sql.Admin.checkLogin, getPara("username"), getPara("password"));
		if(record!=null) {
			setSessionAttr("admin_login_user", record);
			success("登陆成功！！");
		} else 
			fail("用户名或密码错误！！");
	}
	
	@ActionKey("logout")
	public void logout() {
		removeSessionAttr("admin_login_user");
		redirect("/login");
	}
	
	public void reg() {
		String password = getPara("admin.password");
		String repassword = getPara("repassword");
		if(!password.equals(repassword))
			fail("两次输入密码不一致！！");
		else {
			getModel(Admin.class).save();
			success("注册成功！！");
		}
	}

}
